﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace M.SSO
{
	/// <summary>
	/// 常用SSO中验证使用的简单User
	/// </summary>
	public class AuthUser
	{
		/// <summary>
		/// 用户ID
		/// </summary>
		public string ID { get; set; }
		/// <summary>
		/// 用户代码
		/// </summary>
		public string Code { get; set; }
		/// <summary>
		/// 用户密码
		/// </summary>
		public string Password { get; set; }
		/// <summary>
		/// 用户名
		/// </summary>
		public string Name { get; set; }
		/// <summary>
		/// 用户岗位
		/// </summary>
		public string Station { get; set; }
		/// <summary>
		/// 转换到Cookie值集合
		/// </summary>
		/// <returns></returns>
		public System.Collections.Specialized.NameValueCollection ToCookieValues()
		{
			System.Collections.Specialized.NameValueCollection values = new System.Collections.Specialized.NameValueCollection();
			values.Add("ID", this.ID);
			values.Add("Code", Web.Util.UrlEncode(this.Code));
			values.Add("Password", this.Password);
			values.Add("Name", Web.Util.UrlEncode(this.Name));
			values.Add("Station", Web.Util.UrlEncode(this.Station));
			return values;
		}
		/// <summary>
		/// 从Cookie值集合中获取AuthUser
		/// </summary>
		/// <param name="values"></param>
		/// <returns></returns>
		public static AuthUser FromCookieValues(System.Collections.Specialized.NameValueCollection values)
		{
			try
			{
				AuthUser usr = new AuthUser();
				usr.ID = values["ID"];
				usr.Code = Web.Util.UrlDecode(values["Code"]);
				usr.Password = values["Password"];
				usr.Name = Web.Util.UrlDecode(values["Name"]);
				usr.Station = Web.Util.UrlDecode(values["Station"]);
				return usr;
			}
			catch
			{
				return null;
			}
		}
	}
}
